package com.oscar.ehome.presenter;


import android.util.Log;

import com.oscar.ehome.bean.DownBean;
import com.oscar.ehome.bean.RateListBean;
import com.oscar.ehome.bean.messageBean.MessagesBean;
import com.oscar.ehome.bean.pagebean.ClassRoomPrombleBean;
import com.oscar.ehome.bean.pagebean.SginTwoMessageBean;
import com.oscar.ehome.bean.setbean.AlipayBean;
import com.oscar.ehome.bean.setbean.FeedBackBean;
import com.oscar.ehome.bean.setbean.LearnHistoryBean;
import com.oscar.ehome.bean.setbean.PaySuccessBean;
import com.oscar.ehome.bean.setbean.SetMessageBean;
import com.oscar.ehome.bean.setbean.SginMessageBean;
import com.oscar.ehome.bean.setbean.SginchuqinBean;
import com.oscar.ehome.bean.setbean.TokenBean;
import com.oscar.ehome.bean.setbean.WeChatBean;
import com.oscar.ehome.bean.teamBean.UpdateBean;
import com.oscar.ehome.model.HttpModel;
import com.oscar.ehome.model.HttpModelImple;
import com.oscar.ehome.model.OnHttpListener;
import com.oscar.ehome.provider.zxing.client.android.decode.FaceView;
import com.oscar.ehome.view.messageview.view.MessageListView;
import com.oscar.ehome.view.pageview.view.QuestionListView;
import com.oscar.ehome.view.pageview.view.SgintwoDakaView;
import com.oscar.ehome.view.setview.view.DownView;
import com.oscar.ehome.view.setview.view.FeedBackView;
import com.oscar.ehome.view.setview.view.LearnHistoryView;
import com.oscar.ehome.view.setview.view.PayView;
import com.oscar.ehome.view.setview.view.RateListView;
import com.oscar.ehome.view.setview.view.SetView;
import com.oscar.ehome.view.setview.view.SetingView;
import com.oscar.ehome.view.setview.view.SginCountView;
import com.oscar.ehome.view.setview.view.SginDakaView;

/**
 * Created by 柒岇 on 2017/7/7.
 */

public class SetPresenter extends BasePresenter {

    HttpModel httpModel;
    PayView payView;
    FeedBackView feedBackView;
    SetView setView;
    RateListView rateListView;
    DownView downView;
    MessageListView messageListView;
    SginCountView sginCountView;
    SginDakaView sginDakaView;
    LearnHistoryView learnHistoryView;
    SetingView setingView;
    QuestionListView questionListView;
    SgintwoDakaView sgintwoDakaView;

    public SetPresenter(PayView payView) {
        this.httpModel = new HttpModelImple();
        this.payView = payView;
    }

    public SetPresenter(SgintwoDakaView sgintwoDakaView) {
        this.httpModel = new HttpModelImple();
        this.sgintwoDakaView = sgintwoDakaView;
    }

    public SetPresenter(FeedBackView feedBackView) {
        this.httpModel = new HttpModelImple();
        this.feedBackView = feedBackView;
    }

    public SetPresenter(SetView setView) {
        this.httpModel = new HttpModelImple();
        this.setView = setView;
    }

    public SetPresenter(RateListView rateListView) {
        this.httpModel = new HttpModelImple();
        this.rateListView = rateListView;
    }

    public SetPresenter(DownView downView) {
        this.httpModel = new HttpModelImple();
        this.downView = downView;
    }

    public SetPresenter(MessageListView messageListView) {
        this.httpModel = new HttpModelImple();
        this.messageListView = messageListView;
    }

    public SetPresenter(SginCountView sginCountView) {
        this.httpModel = new HttpModelImple();
        this.sginCountView = sginCountView;
    }

    public SetPresenter(SginDakaView sginDakaView) {
        this.httpModel = new HttpModelImple();
        this.sginDakaView = sginDakaView;
    }

    public SetPresenter(LearnHistoryView learnHistoryView) {
        this.httpModel = new HttpModelImple();
        this.learnHistoryView = learnHistoryView;
    }

    public SetPresenter(SetingView setingView) {
        this.httpModel = new HttpModelImple();
        this.setingView = setingView;
    }

    public SetPresenter(QuestionListView questionListView) {
        this.httpModel = new HttpModelImple();
        this.questionListView = questionListView;
    }


    /**
     * 微信预支付
     *
     * @param token
     */
    public void getWeChat(String token) {

        httpModel.getWeChat(token, new OnHttpListener<WeChatBean>() {
            @Override
            public void onSuccess(WeChatBean obj) {
                if (payView != null)
                    payView.getWeChat(obj);
            }

            @Override
            public void onError(String msg) {
                if (payView != null)
                    payView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (payView != null)
                    payView.erroy();
            }
        });
    }

    /**
     * 支付宝预支付
     *
     * @param token
     */
    public void getAlipay(String token) {


        httpModel.getAlipay(token, new OnHttpListener<AlipayBean>() {

            @Override
            public void onSuccess(AlipayBean obj) {
                if (payView != null)
                    payView.getAlipay(obj);
            }

            @Override
            public void onError(String msg) {
                if (payView != null)
                    payView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (payView != null)
                    payView.erroy();
            }
        });
    }

    /**
     * 支付成功
     *
     * @param token
     */
    public void getUserPayInfo(String token) {
        httpModel.getUserPayInfo(token, new OnHttpListener<PaySuccessBean>() {
            @Override
            public void onSuccess(PaySuccessBean obj) {
                if (payView != null)
                    payView.getUserPayInfo(obj);

            }

            @Override
            public void onError(String msg) {
                if (payView != null)
                    payView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (payView != null)
                    payView.erroy();
            }
        });
    }

    /**
     * 获取上传到七牛图片的token值/
     * TokenBean
     */
    public void getUploadToken() {

        httpModel.getUploadToken(new OnHttpListener<TokenBean>() {

            @Override
            public void onSuccess(TokenBean obj) {
                if (feedBackView != null)
                    feedBackView.getUploadToken(obj);
            }

            @Override
            public void onError(String msg) {
                if (feedBackView != null)
                    feedBackView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (feedBackView != null)
                    feedBackView.erroy();
            }
        });

    }

    /**
     * 意见反馈
     */
    public void subMitFeed(String token, String problemDesc, String feedbackType, String mobileSystem, String mobileModel, String versionNo, String imageStr) {
        httpModel.subMitFeed(token, problemDesc, feedbackType, mobileSystem, mobileModel, versionNo, imageStr, new OnHttpListener<FeedBackBean>() {
            @Override
            public void onSuccess(FeedBackBean obj) {
                if (feedBackView != null)
                    feedBackView.subMitFeed(obj);
            }

            @Override
            public void onError(String msg) {

            }

            @Override
            public void onFailure() {
                if (feedBackView != null)
                    feedBackView.erroy();
            }
        });


    }

    /**
     * 版本更新
     *
     * @param versionCode
     */
    public void VersionUpdate(String versionCode) {
        httpModel.VersionUpdate(versionCode, new OnHttpListener<UpdateBean>() {
            @Override
            public void onSuccess(UpdateBean obj) {
                if (setView != null)
                    setView.VersionUpdate(obj);
            }

            @Override
            public void onError(String msg) {
                if (setView != null)
                    setView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (setView != null)
                    setView.erroy();

            }
        });
    }

    /**
     * 评级列表
     *
     * @param token
     */
    public void getRate(String token) {

        httpModel.getRate(token, new OnHttpListener<RateListBean>() {
            @Override
            public void onSuccess(RateListBean obj) {
                if (rateListView != null)
                    rateListView.getRatelist(obj);
            }

            @Override
            public void onError(String msg) {
                if (rateListView != null)
                    rateListView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (rateListView != null)
                    rateListView.erroy();
            }
        });
    }

    /**
     * 下载列表
     *
     * @param token
     */
    public void deleteDownload(String token) {

        httpModel.download(token, new OnHttpListener<DownBean>() {
            @Override
            public void onSuccess(DownBean obj) {
                if (downView != null)
                    downView.DownLoad(obj);
            }

            @Override
            public void onError(String msg) {
                if (downView != null)
                    downView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (downView != null)
                    downView.erroy();
            }
        });
    }

    /**
     * 我的发布列表
     *
     * @param token
     */
    public void issuseMessage(String token) {

        httpModel.MyissusseMessage(token, new OnHttpListener<MessagesBean>() {
            @Override
            public void onSuccess(MessagesBean obj) {
                if (messageListView != null)
                    messageListView.getMessageList(obj);
            }

            @Override
            public void onError(String msg) {
                if (messageListView != null)
                    messageListView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (messageListView != null)
                    messageListView.erroy();
            }
        });
    }

    /**
     * 我的发布列表
     *
     * @param token
     */
    public void deleteIssuseMessage(String token, String id) {

        httpModel.DeleteMyissusseMessage(token, id, new OnHttpListener<String>() {
            @Override
            public void onSuccess(String obj) {
                if (messageListView != null)
                    messageListView.deleteMessageList(obj);
            }

            @Override
            public void onError(String msg) {
                if (messageListView != null)
                    messageListView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (messageListView != null)
                    messageListView.erroy();
            }
        });
    }

    /**
     * 我的打卡列表
     *
     * @param token
     */
    public void getSginLIst(String token, String statisticsTime) {

        httpModel.getSginList(token, statisticsTime, new OnHttpListener<SginchuqinBean>() {
            @Override
            public void onSuccess(SginchuqinBean obj) {
                if (sginCountView != null)
                    sginCountView.getSginlist(obj);
            }

            @Override
            public void onError(String msg) {
                if (sginCountView != null)
                    sginCountView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (sginCountView != null)
                    sginCountView.erroy();
            }
        });
    }

    /**
     * 我的打卡列表
     *
     * @param token
     */
    public void getSgintwoList(String token, String statisticsTime) {

        httpModel.getSgintwoList(token, statisticsTime, new OnHttpListener<SginchuqinBean>() {
            @Override
            public void onSuccess(SginchuqinBean obj) {
                if (sginCountView != null)
                    sginCountView.getSgintwolist(obj);
            }

            @Override
            public void onError(String msg) {
                if (sginCountView != null)
                    sginCountView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (sginCountView != null)
                    sginCountView.erroy();
            }
        });
    }

    /**
     * 请求打卡信息
     *
     * @param token
     */
    public void getSginMessage(String token) {

        httpModel.getSginMessage(token, new OnHttpListener<SginMessageBean>() {
            @Override
            public void onSuccess(SginMessageBean obj) {
                if (sginDakaView != null)
                    sginDakaView.getSginMessage(obj);
            }

            @Override
            public void onError(String msg) {
                if (sginDakaView != null)
                    sginDakaView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (sginDakaView != null)
                    sginDakaView.erroy();
            }
        });
    }

    /**
     * 打卡
     *
     * @param token
     */
    public void setDaka(String token, String lng, String lat, String address) {

        httpModel.setDakas(token, lng, lat, address, new OnHttpListener<String>() {
            @Override
            public void onSuccess(String obj) {
                if (sginDakaView != null)
                    sginDakaView.setSgin(obj);
            }

            @Override
            public void onError(String msg) {
                if (sginDakaView != null)
                    sginDakaView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (sginDakaView != null)
                    sginDakaView.erroy();
            }
        });
    }

    /**
     * 学习历史记录
     *
     * @param token
     */
    public void getLearnList(String token, String pageSize, String pageNo) {

        httpModel.getLearnList(token,pageSize,pageNo, new OnHttpListener<LearnHistoryBean>() {
            @Override
            public void onSuccess(LearnHistoryBean obj) {
                if (learnHistoryView != null)
                    learnHistoryView.getLearnList(obj);
            }

            @Override
            public void onError(String msg) {
                if (learnHistoryView != null)
                    learnHistoryView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (learnHistoryView != null)
                    learnHistoryView.erroy();
            }
        });
    }

    /**
     * 打卡
     *
     * @param token
     */
    public void getMessages(String token) {

        httpModel.getMessages(token, new OnHttpListener<SetMessageBean>() {
            @Override
            public void onSuccess(SetMessageBean obj) {
                if (setingView != null)
                    setingView.getMessage(obj);
            }

            @Override
            public void onError(String msg) {
                if (setingView != null)
                    setingView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (setingView != null)
                    setingView.erroy();
            }
        });
    }

    /**
     * 查询我提问的问题列表
     *
     * @param token
     */
    public void getMyQuestionList(String token, String pageNo, String pageSize) {

        httpModel.getMyQuestionList(token, pageNo, pageSize, new OnHttpListener<ClassRoomPrombleBean>() {
            @Override
            public void onSuccess(ClassRoomPrombleBean obj) {
                if (questionListView != null)
                    questionListView.getKnowPrombles(obj);
            }

            @Override
            public void onError(String msg) {
                if (questionListView != null)
                    questionListView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (questionListView != null)
                    questionListView.erroy();
            }
        });
    }

    /**
     * 打卡
     *
     * @param token
     */
    public void settwoDaka(String token, String lng, String lat, String address) {

        httpModel.settwoDakas(token, lng, lat, address, new OnHttpListener<String>() {
            @Override
            public void onSuccess(String obj) {
                if (sgintwoDakaView != null)
                    sgintwoDakaView.setSgin(obj);
            }

            @Override
            public void onError(String msg) {
                if (sgintwoDakaView != null)
                    sgintwoDakaView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (sgintwoDakaView != null)
                    sgintwoDakaView.erroy();
            }
        });
    }

    /**
     * 请求打卡信息
     *
     * @param token
     */
    public void getSgintwoMessage(String token) {

        httpModel.getSgintwoMessage(token, new OnHttpListener<SginTwoMessageBean>() {
            @Override
            public void onSuccess(SginTwoMessageBean obj) {
                if (sgintwoDakaView != null)
                    sgintwoDakaView.getSgintwoMessage(obj);

            }

            @Override
            public void onError(String msg) {
                if (sgintwoDakaView != null)
                    sgintwoDakaView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (sgintwoDakaView != null)
                    sgintwoDakaView.erroy();
            }
        });
    }

}